<?php

namespace Home\Model;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Select;


class VisitTable extends AbstractTableGateway {

    protected $table = 'visits';
	

    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new Visit());

        $this->initialize();
    }

    
	
	 public function fetchAll(Select $select = null) {
        if (null === $select)
            $select = new Select();
        $select->from($this->table,array('*'));
        $resultSet = $this->selectWith($select);
        $resultSet->buffer();
        return $resultSet;
    }
	
	public function check_date($ngay,$thang,$nam)
	{
		
		$resultSet = $this->select(array('ngay'=>$ngay,'thang'=>$thang,'nam'=>$nam));
    	$row = $resultSet->current();
        return $row;
		
	}
	
	public function check_ip($ip,$ngay,$thang,$nam)
	{
		
		$resultSet = $this->select(array('ip_address'=>$ip,'ngay'=>$ngay,'thang'=>$thang,'nam'=>$nam));
    	$row = $resultSet->current();
        return $row;
		
	}
	public function deleteVisit()
	{
		
		$this->delete('id != 0');
		
	}
	public function insertVisit($ip,$session,$ngay,$thang,$nam)
	{
		$data = array(
			'ip_address' => $ip,
			'session' => $session,
			'ngay' => $ngay,
			'thang' => $thang,
			'nam' => $nam,
		);
		$this->insert($data);
		
	}
	public function updateVisit($ip,$session,$ngay,$thang,$nam)
	{
		$data = array(
			
			'session' => $session,
			
		);
		$this->update($data,array('ip_address' => $ip,'ngay'=>$ngay,'thang'=>$thang,'nam'=>$nam));
		
	}


}
